package br.org.acessobrasil.processoacessibilidade.dao;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Transactional
public abstract class SuperDao<T>  {
	private EntityManager entityManager;
	public EntityManager getEntityManager() {
		return entityManager;
	}
	@PersistenceContext
	public void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;
	}
	public T create(T obj){
		try {
			getEntityManager().persist(obj);
		}catch (Exception e) {
			e.printStackTrace();
		}
		return obj;
	}
	public void delete(T obj){
		getEntityManager().remove(obj);
	}
	/**
	 * Merge the state of the given entity into the current persistence context. 
	 * @param obj entity
	 */
	public void update(T obj){
		getEntityManager().merge(obj);
	}
	public abstract T find(long id);
}
